﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKArchUtils.Utils;
using YJKRevitPreview;
using YJKRevitKernel.RevitDimensionUtility;

namespace YJKRevitAxisModule
{
	public partial class ArcAxisForm : System.Windows.Forms.Form
	{
		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
		internal static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

		public ArcAxisForm()
		{
			this.pictureBox3 = new Previewer(3u);
			this.InitializeComponent();
			this.m_dataFromDlg = new ArcAxisDataFromDlg();
			this.m_bExpand = false;
		}

		public ArcAxisForm(ExternalCommandData cmdData)
		{
			this.InitializeComponent();
			this.pictureBox3 = new Previewer(3u);
			base.Controls.Add(this.pictureBox3);
			this.pictureBox3.BackColor = System.Drawing.Color.White;
			this.pictureBox3.BorderStyle = BorderStyle.FixedSingle;
			this.pictureBox3.Location = this.panelPreview.Location;
			this.pictureBox3.Name = "pictureBox3";
			this.pictureBox3.Size = this.panelPreview.Size;
			this.pictureBox3.SizeMode = PictureBoxSizeMode.AutoSize;
			this.pictureBox3.TabIndex = 51;
			this.pictureBox3.TabStop = false;
			this.pictureBox3.Paint += this.pictureBox3_Paint;
			this.m_dataFromDlg = new ArcAxisDataFromDlg();
			this.revit = cmdData;
			this.m_docment = cmdData.Application.ActiveUIDocument.Document;
			this.m_bExpand = false;
			this.Number = new DataGridViewTextBoxColumn();
			this.Number.HeaderText = "数目";
			this.Number.DataPropertyName = "Number";
			this.Number.Width = 52;
			this.Dist = new DataGridViewTextBoxColumn();
			this.Dist.HeaderText = "距离";
			this.Dist.DataPropertyName = "Dist";
			this.Dist.Width = 63;
			this.gridView.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Number,
				this.Dist
			});
			this.bindingSourceDist.DataSource = typeof(AxisListItem);
			this.bindingSourceAngle.DataSource = typeof(AxisListItem);
			this.gridView.AutoGenerateColumns = false;
			this.gridView.DataSource = this.bindingSourceDist;
			this.bindingSourceDist.DataSource = this.m_dataFromDlg.DistData;
			this.bindingSourceAngle.DataSource = this.m_dataFromDlg.AngleData;
			this.InitCmbGridType();
			this.InitCmbDimType();
			this.InitCmbAxisStyle();
			if (this.ReadAxisData())
			{
				this.RefreshControls();
				this.m_dataFromDlg.ExtendA = Convert.ToDouble(this.extendA.Text);
				this.m_dataFromDlg.ExtendL = Convert.ToDouble(this.extendL.Text);
				this.m_dataFromDlg.StartAngle = Convert.ToDouble(this.textBoxAngle.Text);
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void radioDist_CheckedChanged(object sender, EventArgs e)
		{
			this.FilterNullRow();
			this.gridView.DataSource = this.bindingSourceDist;
			this.m_PreviousDataSourceType = ArcAxisForm.DataSourceType.DST_DIST;
			this.ResetList();
			this.Dist = (DataGridViewTextBoxColumn)this.gridView.Columns[1];
			this.Dist.HeaderText = "距离";
		}

		private void radioAngle_CheckedChanged(object sender, EventArgs e)
		{
			this.FilterNullRow();
			this.gridView.DataSource = this.bindingSourceAngle;
			this.m_PreviousDataSourceType = ArcAxisForm.DataSourceType.DST_ANGLE;
			this.ResetList();
			this.Dist = (DataGridViewTextBoxColumn)this.gridView.Columns[1];
			this.Dist.HeaderText = "角度";
		}

		private void cmbXStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cmbXStyle.SelectedIndex == 0)
			{
				string largestAlpha = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxXStart.Text = largestAlpha;
				this.cmbYStyle.SelectedIndex = 1;
				string text = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxYStart.Text = text;
				return;
			}
			if (this.cmbXStyle.SelectedIndex == 1)
			{
				string text2 = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxXStart.Text = text2;
				this.cmbYStyle.SelectedIndex = 0;
				string largestAlpha2 = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxYStart.Text = largestAlpha2;
			}
		}

		private void cmbYStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cmbYStyle.SelectedIndex == 0)
			{
				string largestAlpha = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxYStart.Text = largestAlpha;
				this.cmbXStyle.SelectedIndex = 1;
				string text = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxXStart.Text = text;
				return;
			}
			if (this.cmbYStyle.SelectedIndex == 1)
			{
				string text2 = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxYStart.Text = text2;
				this.cmbXStyle.SelectedIndex = 0;
				string largestAlpha2 = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxXStart.Text = largestAlpha2;
			}
		}

		private void textBoxXStart_Leave(object sender, EventArgs e)
		{
			string text = this.textBoxXStart.Text;
			if (this.cmbXStyle.SelectedIndex == 0)
			{
				if (AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
				{
					new DlgMessage("径线起始轴号已经存在，请重新输入").ShowDialog();
					this.textBoxXStart.Focus();
					this.textBoxXStart.SelectAll();
					return;
				}
			}
			else if (this.cmbXStyle.SelectedIndex == 1 && AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
			{
				new DlgMessage("径线起始轴号已经存在，请重新输入").ShowDialog();
				this.textBoxXStart.Focus();
				this.textBoxXStart.SelectAll();
			}
		}

		private void textBoxYStart_Leave(object sender, EventArgs e)
		{
			string text = this.textBoxYStart.Text;
			if (this.cmbYStyle.SelectedIndex == 0)
			{
				if (AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
				{
					new DlgMessage("弧线起始轴号已经存在，请重新输入").ShowDialog();
					this.textBoxYStart.Focus();
					this.textBoxYStart.SelectAll();
					return;
				}
			}
			else if (this.cmbYStyle.SelectedIndex == 1 && AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
			{
				new DlgMessage("弧线起始轴号已经存在，请重新输入").ShowDialog();
				this.textBoxYStart.Focus();
				this.textBoxYStart.SelectAll();
			}
		}

		private void btnLoad_Click(object sender, EventArgs e)
		{
			if (this.ReadAxisData())
			{
				this.RefreshControls();
				this.m_dataFromDlg.ExtendA = Convert.ToDouble(this.extendA.Text);
				this.m_dataFromDlg.ExtendL = Convert.ToDouble(this.extendL.Text);
				this.m_dataFromDlg.StartAngle = Convert.ToDouble(this.textBoxAngle.Text);
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void btnClean_Click(object sender, EventArgs e)
		{
			if (this.radioDist.Checked)
			{
				this.bindingSourceDist.Clear();
			}
			else if (this.radioAngle.Checked)
			{
				this.bindingSourceAngle.Clear();
			}
			this.RefreshControls();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (!this.checkBoxSameAxis.Checked)
			{
				if (!this.DataIsCorrect())
				{
					return;
				}
			}
			else if (!this.PublicDataIsCorrect())
			{
				return;
			}
			this.m_dataFromDlg.SameAxis = this.checkBoxSameAxis.Checked;
			this.m_dataFromDlg.Clockwise = this.checkBoxClockwise.Checked;
			this.m_dataFromDlg.InnerRadius = ((this.textBoxInnerRadius.Text == "") ? 0.0 : Convert.ToDouble(this.textBoxInnerRadius.Text));
			this.m_dataFromDlg.StartAngle = ((this.textBoxAngle.Text == "") ? 0.0 : Convert.ToDouble(this.textBoxAngle.Text));
			this.m_dataFromDlg.GridType = this.cmbGridType.SelectedItem.ToString();
			this.m_dataFromDlg.WithDim = this.checkBoxDim.Checked;
			this.m_dataFromDlg.LineDimType = ((ShowDimensionType)this.cmbAlignDimType.SelectedItem).Type;
			this.m_dataFromDlg.ArcDimType = ((ShowDimensionType)this.cmbArcDimType.SelectedItem).Type;
			this.m_dataFromDlg.XStyle = this.cmbXStyle.SelectedIndex;
			this.m_dataFromDlg.XStart = this.textBoxXStart.Text;
			this.m_dataFromDlg.XReverse = this.checkBoxXRev.Checked;
			this.m_dataFromDlg.YStyle = this.cmbXStyle.SelectedIndex;
			this.m_dataFromDlg.YStart = this.textBoxYStart.Text;
			this.m_dataFromDlg.YReverse = this.checkBoxYRev.Checked;
			this.m_dataFromDlg.ExtendL = ((this.extendL.Text == "") ? 0.0 : Convert.ToDouble(this.extendL.Text));
			this.m_dataFromDlg.ExtendA = ((this.extendA.Text == "") ? 0.0 : Convert.ToDouble(this.extendA.Text));
			this.m_dataFromDlg.Up = this.cbxUp.Checked;
			this.m_dataFromDlg.Down = this.cbxDown.Checked;
			this.m_dataFromDlg.Left = this.cbxLeft.Checked;
			this.m_dataFromDlg.Right = this.cbxRight.Checked;
			this.SaveAxisData();
			base.DialogResult = DialogResult.OK;
		}

		private bool DataIsCorrect()
		{
			string text = "ABCDEFGHJKLMNPQRSTUVWXY1234567890-_";
			if (this.m_dataFromDlg.AngleData.Count < 1 || this.m_dataFromDlg.DistData.Count < 1)
			{
				new DlgMessage("进深或角度数据不能为空，请检查！").ShowDialog();
				return false;
			}
			if (this.textBoxXStart.Text == "")
			{
				new DlgMessage("径线起始轴号为空，请检查！").ShowDialog();
				this.textBoxXStart.Focus();
				return false;
			}
			if (this.textBoxYStart.Text == "")
			{
				new DlgMessage("弧线起始轴号为空，请检查！").ShowDialog();
				this.textBoxYStart.Focus();
				return false;
			}
			for (int i = 0; i < this.textBoxXStart.Text.Length; i++)
			{
				if (!text.Contains(this.textBoxXStart.Text.Substring(i, 1)))
				{
					new DlgMessage("径线起始轴号含有非法字符，请检查！").ShowDialog();
					this.textBoxXStart.Focus();
					return false;
				}
			}
			for (int j = 0; j < this.textBoxYStart.Text.Length; j++)
			{
				if (!text.Contains(this.textBoxYStart.Text.Substring(j, 1)))
				{
					new DlgMessage("弧线起始轴号含有非法字符，请检查！").ShowDialog();
					this.textBoxYStart.Focus();
					return false;
				}
			}
			if (this.checkBoxDim.Checked && this.cmbAlignDimType.SelectedItem == null)
			{
				new DlgMessage("请先选择一种线形标注样式!").ShowDialog();
				this.cmbAlignDimType.Focus();
				return false;
			}
			if (this.checkBoxSameAxis.Checked && this.gridView.RowCount == 1)
			{
				new DlgMessage("请先输入轴网角度!").ShowDialog();
				this.listDist.Focus();
				return false;
			}
			return true;
		}

		private bool PublicDataIsCorrect()
		{
			string text = "ABCDEFGHJKLMNPQRSTUVWXY1234567890-_";
			if (this.textBoxXStart.Text == "")
			{
				new DlgMessage("径线起始轴号为空，请检查！").ShowDialog();
				this.textBoxXStart.Focus();
				return false;
			}
			if (this.textBoxYStart.Text == "")
			{
				new DlgMessage("弧线起始轴号为空，请检查！").ShowDialog();
				this.textBoxYStart.Focus();
				return false;
			}
			for (int i = 0; i < this.textBoxXStart.Text.Length; i++)
			{
				if (!text.Contains(this.textBoxXStart.Text.Substring(i, 1)))
				{
					new DlgMessage("径线起始轴号含有非法字符，请检查！").ShowDialog();
					this.textBoxXStart.Focus();
					return false;
				}
			}
			for (int j = 0; j < this.textBoxYStart.Text.Length; j++)
			{
				if (!text.Contains(this.textBoxYStart.Text.Substring(j, 1)))
				{
					new DlgMessage("弧线起始轴号含有非法字符，请检查！").ShowDialog();
					this.textBoxYStart.Focus();
					return false;
				}
			}
			if (this.checkBoxDim.Checked && this.cmbAlignDimType.SelectedItem == null)
			{
				new DlgMessage("请先选择一种线形标注样式!").ShowDialog();
				this.cmbAlignDimType.Focus();
				return false;
			}
			if (this.checkBoxSameAxis.Checked && this.gridView.RowCount <= 1)
			{
				new DlgMessage("请先输入轴网角度!").ShowDialog();
				this.listDist.Focus();
				return false;
			}
			return true;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
		}

		private void listDist_MouseClick(object sender, MouseEventArgs e)
		{
			double num = Convert.ToDouble(this.listDist.SelectedItem);
			if (this.listDist.SelectedItem != null)
			{
				if (this.radioAngle.Checked)
				{
					double num2 = num;
					foreach (object obj in ((IEnumerable)this.gridView.Rows))
					{
						DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
						num2 += Convert.ToDouble(dataGridViewRow.Cells[1].Value);
					}
					if (num2 >= 360.0)
					{
						YJKMessageBox.Show("角度和不能大于360度。");
						return;
					}
				}
				if (((ListBox)sender).IndexFromPoint(e.X, e.Y) != -1)
				{
					if (this.radioDist.Checked)
					{
						this.AddRow(this.m_dataFromDlg.DistData, this.bindingSourceDist, num);
					}
					else if (this.radioAngle.Checked)
					{
						this.AddRow(this.m_dataFromDlg.AngleData, this.bindingSourceAngle, num);
					}
					this.RefreshControls();
					this.IsChange = true;
					this.pictureBox3.Refresh();
				}
			}
		}

		private void AddRow(List<AxisListItem> data, BindingSource bSource, double dist)
		{
			if (data.Count < 1)
			{
				bSource.Add(new AxisListItem(1, dist));
				return;
			}
			if (Geometry.IsEqual(data[data.Count - 1].Dist, 0.0))
			{
				int number = data[data.Count - 1].Number;
				bSource.List[bSource.List.Count - 1] = new AxisListItem(number, dist);
				bSource.ResetBindings(false);
				return;
			}
			bSource.Add(new AxisListItem(1, dist));
		}

		private void listDist_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private void checkBoxSameAxis_CheckedChanged(object sender, EventArgs e)
		{
			this.textBoxAngle.Enabled = !this.checkBoxSameAxis.Checked;
			this.cbxLeft.Enabled = !this.checkBoxSameAxis.Checked;
			this.cbxRight.Enabled = !this.checkBoxSameAxis.Checked;
			this.cbxDown.Enabled = !this.checkBoxSameAxis.Checked;
			this.cbxUp.Enabled = !this.checkBoxSameAxis.Checked;
			this.radioDist.Enabled = !this.checkBoxSameAxis.Checked;
			this.checkBoxClockwise.Enabled = !this.checkBoxSameAxis.Checked;
			this.textBoxInnerRadius.Enabled = !this.checkBoxSameAxis.Checked;
			this.btnLoad.Enabled = !this.checkBoxSameAxis.Checked;
			this.btnClean.Enabled = !this.checkBoxSameAxis.Checked;
			this.radioAngle.Checked = true;
			this.cmbAlignDimType.Enabled = !this.checkBoxSameAxis.Checked;
			this.cmbXStyle.Enabled = !this.checkBoxSameAxis.Checked;
			this.cmbYStyle.Enabled = !this.checkBoxSameAxis.Checked;
			this.checkBoxXRev.Enabled = !this.checkBoxSameAxis.Checked;
			this.checkBoxYRev.Enabled = !this.checkBoxSameAxis.Checked;
			this.textBoxXStart.Enabled = !this.checkBoxSameAxis.Checked;
			this.textBoxYStart.Enabled = !this.checkBoxSameAxis.Checked;
		}

		private void checkBoxDim_CheckedChanged(object sender, EventArgs e)
		{
			this.cmbAlignDimType.Enabled = this.checkBoxDim.Checked;
			this.m_dataFromDlg.WithDim = this.checkBoxDim.Checked;
			this.IsChange = true;
			this.Refresh();
		}

		private void checkBoxClockwise_CheckedChanged(object sender, EventArgs e)
		{
			this.m_dataFromDlg.Clockwise = this.checkBoxClockwise.Checked;
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void btnMoreParam_Click(object sender, EventArgs e)
		{
			this.m_bExpand = !this.m_bExpand;
			if (this.m_bExpand)
			{
				this.btnMoreParam.Text = "精简";
			}
			else
			{
				this.btnMoreParam.Text = "更多";
			}
			this.ShowHideMoreParam();
		}

		private void ShowHideMoreParam()
		{
			if (this.m_bExpand)
			{
				ArcAxisForm.MoveWindow(base.Handle, base.Left, base.Top, base.Right - base.Left, base.Bottom - base.Top + 120, true);
				return;
			}
			ArcAxisForm.MoveWindow(base.Handle, base.Left, base.Top, base.Right - base.Left, base.Bottom - base.Top - 120, true);
		}

		private void RefreshControls()
		{
			double num = 0.0;
			for (int i = 0; i < this.m_dataFromDlg.DistData.Count; i++)
			{
				num += this.m_dataFromDlg.DistData.ElementAt(i).Dist * (double)this.m_dataFromDlg.DistData.ElementAt(i).Number;
			}
			double num2 = 0.0;
			for (int j = 0; j < this.m_dataFromDlg.AngleData.Count; j++)
			{
				num2 += this.m_dataFromDlg.AngleData.ElementAt(j).Dist * (double)this.m_dataFromDlg.AngleData.ElementAt(j).Number;
			}
			this.textBoxWidth.Text = Convert.ToString(num2);
			this.textBoxDepth.Text = Convert.ToString(num);
			this.cmbAlignDimType.Enabled = this.checkBoxDim.Checked;
		}

		private void InitCmbGridType()
		{
			foreach (GridType gridType in Common.GetGridTypes(this.m_docment))
			{
				GridType gridType2 = gridType as GridType;
				if (gridType2.Name.IndexOf('_') < 0)
				{
					this.cmbGridType.Items.Add(gridType2.Name);
				}
			}
			if (this.cmbGridType.Items.Count > 0)
			{
				this.cmbGridType.SelectedIndex = 0;
			}
		}

		private DimensionType GetHYAxisDimType()
		{
			DimensionType result = null;
			Transaction transaction = new Transaction(this.m_docment, "GetHYAxisDimType");
			try
			{
				transaction.Start();
				result = RevitDimensionUtiltyMethod.GetDimensionType(this.m_docment, DimensionTypeEnum.AxisDimension, null);
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
			return result;
		}

		private void InitCmbDimType()
		{
			ShowDimensionType item = new ShowDimensionType(this.GetHYAxisDimType());
			this.cmbAlignDimType.Items.Add(item);
			foreach (DimensionType dimensionType in Common.GetDimensionTypes(this.m_docment))
			{
				DimensionType dimensionType2 = dimensionType as DimensionType;
				if (dimensionType2.StyleType == null)
				{
					Parameter parameter = dimensionType2.get_Parameter(BuiltInParameter.DIM_WITNS_LINE_EXTENSION_BELOW);
					if (parameter != null && !parameter.IsReadOnly)
					{
						ShowDimensionType showDimensionType = new ShowDimensionType(dimensionType2);
						if (!this.cmbAlignDimType.Items.Contains(showDimensionType) && !showDimensionType.Type.Name.Contains("@hy2"))
						{
							this.cmbAlignDimType.Items.Add(showDimensionType);
						}
					}
				}
				else if ((int)dimensionType2.StyleType == 1)
				{
					ShowDimensionType showDimensionType2 = new ShowDimensionType(dimensionType2);
					if (!this.cmbArcDimType.Items.Contains(showDimensionType2))
					{
						this.cmbArcDimType.Items.Add(showDimensionType2);
					}
				}
			}
			if (this.cmbAlignDimType.Items.Count > 0)
			{
				this.cmbAlignDimType.SelectedIndex = 0;
			}
			if (this.cmbArcDimType.Items.Count > 0)
			{
				this.cmbArcDimType.SelectedIndex = 0;
			}
		}

		private void InitCmbAxisStyle()
		{
			this.cmbXStyle.SelectedIndex = 1;
			this.cmbYStyle.SelectedIndex = 0;
		}

		private void ResetList()
		{
			this.listDist.Items.Clear();
			if (this.radioDist.Checked)
			{
				using (List<string>.Enumerator enumerator = new List<string>
				{
					"1500",
					"1800",
					"2100",
					"2400",
					"2700",
					"3000",
					"3300",
					"3600",
					"3900",
					"4200",
					"4500",
					"4800",
					"5100",
					"5400"
				}.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string item = enumerator.Current;
						this.listDist.Items.Add(item);
					}
					return;
				}
			}
			if (this.radioAngle.Checked)
			{
				foreach (string item2 in new List<string>
				{
					"10",
					"15",
					"20",
					"25",
					"30",
					"35",
					"40",
					"45",
					"60",
					"90",
					"120",
					"150"
				})
				{
					this.listDist.Items.Add(item2);
				}
			}
		}

		private void SaveAxisData()
		{
			FileStream fileStream = new FileStream(Product.UserDataLocation + "\\ArcAxis.dat", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			string text = Convert.ToString(this.m_dataFromDlg.StartAngle);
			streamWriter.WriteLine(text);
			text = "";
			for (int i = 0; i < this.bindingSourceDist.Count; i++)
			{
				this.bindingSourceDist.Position = i;
				AxisListItem axisListItem = this.bindingSourceDist.Current as AxisListItem;
				text = string.Concat(new string[]
				{
					text,
					Convert.ToString(axisListItem.Number),
					"*",
					Convert.ToString(axisListItem.Dist),
					" "
				});
			}
			streamWriter.WriteLine(text);
			text = "";
			for (int j = 0; j < this.bindingSourceAngle.Count; j++)
			{
				this.bindingSourceAngle.Position = j;
				AxisListItem axisListItem = this.bindingSourceAngle.Current as AxisListItem;
				text = string.Concat(new string[]
				{
					text,
					Convert.ToString(axisListItem.Number),
					"*",
					Convert.ToString(axisListItem.Dist),
					" "
				});
			}
			streamWriter.WriteLine(text);
			streamWriter.WriteLine(this.cmbGridType.SelectedItem.ToString());
			streamWriter.WriteLine(this.checkBoxDim.Checked);
			streamWriter.WriteLine(this.cmbAlignDimType.SelectedItem.ToString());
			streamWriter.WriteLine(this.cmbArcDimType.SelectedItem.ToString());
			streamWriter.WriteLine(this.textBoxInnerRadius.Text);
			streamWriter.WriteLine(this.checkBoxClockwise.Checked);
			text = Convert.ToString(this.m_dataFromDlg.ExtendL);
			streamWriter.WriteLine(text);
			text = Convert.ToString(this.m_dataFromDlg.ExtendA);
			streamWriter.WriteLine(text);
			streamWriter.WriteLine(this.cbxUp.Checked);
			streamWriter.WriteLine(this.cbxDown.Checked);
			streamWriter.WriteLine(this.cbxLeft.Checked);
			streamWriter.WriteLine(this.cbxRight.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private bool ReadDataByProjectSetting()
		{
			if (this.cmbGridType.Items.Count > 0)
			{
				this.cmbGridType.SelectedIndex = 0;
			}
			if (this.cmbAlignDimType.Items.Count > 0)
			{
				this.cmbAlignDimType.SelectedIndex = 0;
			}
			if (this.cmbArcDimType.Items.Count > 0)
			{
				this.cmbArcDimType.SelectedIndex = 0;
			}
			return true;
		}

		private bool ReadAxisData()
		{
			string text = Product.UserDataLocation + "\\ArcAxis.dat";
			FileInfo fileInfo = new FileInfo(text);
			if (!File.Exists(text))
			{
				return this.ReadDataByProjectSetting();
			}
			FileStream fileStream = new FileStream(text, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			try
			{
				streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
				string text2 = streamReader.ReadLine();
				this.textBoxAngle.Text = text2;
				text2 = streamReader.ReadLine();
				this.String2DistArray(text2, ref this.bindingSourceDist);
				text2 = streamReader.ReadLine();
				this.String2DistArray(text2, ref this.bindingSourceAngle);
				text2 = streamReader.ReadLine();
				this.cmbGridType.SelectedItem = text2;
				text2 = streamReader.ReadLine();
				this.checkBoxDim.Checked = Convert.ToBoolean(text2);
				text2 = streamReader.ReadLine();
				this.cmbAlignDimType.SelectedItem = text2;
				text2 = streamReader.ReadLine();
				this.cmbArcDimType.SelectedItem = text2;
				text2 = streamReader.ReadLine();
				this.textBoxInnerRadius.Text = text2;
				text2 = streamReader.ReadLine();
				this.checkBoxClockwise.Checked = Convert.ToBoolean(text2);
				text2 = streamReader.ReadLine();
				this.extendL.Text = text2;
				text2 = streamReader.ReadLine();
				this.extendA.Text = text2;
				text2 = streamReader.ReadLine();
				this.cbxUp.Checked = Convert.ToBoolean(text2);
				text2 = streamReader.ReadLine();
				this.cbxDown.Checked = Convert.ToBoolean(text2);
				text2 = streamReader.ReadLine();
				this.cbxLeft.Checked = Convert.ToBoolean(text2);
				text2 = streamReader.ReadLine();
				this.cbxRight.Checked = Convert.ToBoolean(text2);
				streamReader.Close();
				fileStream.Close();
			}
			catch (Exception)
			{
				streamReader.Close();
				fileStream.Close();
				fileInfo.Delete();
			}
			return true;
		}

		private void String2DistArray(string lineData, ref BindingSource bindingSource)
		{
			bindingSource.Clear();
			string[] array = lineData.Split(new char[]
			{
				' '
			});
			for (int i = 0; i < array.Length; i++)
			{
				string[] source = array[i].Split(new char[]
				{
					'*'
				});
				if (source.Count<string>() == 2)
				{
					AxisListItem axisListItem = new AxisListItem();
					axisListItem.Number = Convert.ToInt32(source.ElementAt(0));
					axisListItem.Dist = Convert.ToDouble(source.ElementAt(1));
					bindingSource.Add(axisListItem);
				}
			}
		}

		private void gridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
		{
			if (this.gridView.CurrentCell.ColumnIndex == 0 || this.gridView.CurrentCell.ColumnIndex == 1)
			{
				this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
				this.EditingControl.KeyPress += this.EditingControl_KeyPress;
				this.EditingControl.TextChanged += this.EditingControl_TextChanged;
			}
		}

		private void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
			int rowIndex = e.RowIndex;
		}

		private void gridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
		{
			if (e.ColumnIndex == 0 || e.ColumnIndex == 1)
			{
				System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox();
				if (this.gridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
				{
					textBox.Text = "";
				}
				else
				{
					textBox.Text = this.gridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
				}
				this.NotePastText(textBox, ref this.PastText);
			}
		}

		private void gridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			this.EditingControl.KeyPress -= this.EditingControl_KeyPress;
			this.EditingControl.TextChanged -= this.EditingControl_TextChanged;
			this.RefreshControls();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void EditingControl_TextChanged(object sender, EventArgs e)
		{
			if (this.IsNumeric(this.EditingControl.Text, true, false))
			{
				this.NotePastText(this.EditingControl, ref this.PastText);
				return;
			}
			this.RestoreText(this.EditingControl, this.PastText);
		}

		private void EditingControl_KeyPress(object sender, KeyPressEventArgs e)
		{
			this.CheckKeyIn(e, false);
		}

		private bool IsNumeric(string NumStr, bool MayEmpty, bool ContainDot)
		{
			if ((NumStr ?? "") == "")
			{
				return MayEmpty;
			}
			if (ContainDot)
			{
				int num = NumStr.IndexOf('.');
				if (num >= 0)
				{
					num = NumStr.IndexOf('.', num + 1);
					if (num >= 0)
					{
						return false;
					}
				}
			}
			else if (NumStr.IndexOf('.') >= 0)
			{
				return false;
			}
			char[] array = NumStr.ToCharArray();
			for (int i = 0; i <= array.GetUpperBound(0); i++)
			{
				if (!char.IsDigit(array[i]))
				{
					if (array[i] != '.')
					{
						return false;
					}
					if (!ContainDot)
					{
						return false;
					}
				}
			}
			return !ContainDot || NumStr.Replace('.', '\0').Length > 0;
		}

		private void CheckKeyIn(KeyPressEventArgs Key, bool AllowDot)
		{
			if (char.IsControl(Key.KeyChar))
			{
				return;
			}
			if (char.IsDigit(Key.KeyChar))
			{
				return;
			}
			if (Key.KeyChar == '.')
			{
				if (!AllowDot)
				{
					Key.KeyChar = '\0';
				}
				return;
			}
			Key.KeyChar = '\0';
		}

		private void NotePastText(DataGridViewTextBoxEditingControl txtFrom, ref ArcAxisForm.struPastText NoteTo)
		{
			if (txtFrom.Text == "" || txtFrom.Text == null)
			{
				txtFrom.Text = "0";
			}
			NoteTo.Text = txtFrom.Text;
			NoteTo.SelStart = txtFrom.SelectionStart;
			NoteTo.SelLength = txtFrom.SelectionLength;
		}

		private void NotePastText(System.Windows.Forms.TextBox txtFrom, ref ArcAxisForm.struPastText NoteTo)
		{
			if (txtFrom.Text == "" || txtFrom.Text == null)
			{
				txtFrom.Text = "0";
			}
			NoteTo.Text = txtFrom.Text;
			NoteTo.SelStart = txtFrom.SelectionStart;
			NoteTo.SelLength = txtFrom.SelectionLength;
		}

		private void RestoreText(DataGridViewTextBoxEditingControl txtRestoreTo, ArcAxisForm.struPastText TextFrom)
		{
			txtRestoreTo.Text = TextFrom.Text;
			txtRestoreTo.SelectionStart = TextFrom.SelStart;
			txtRestoreTo.SelectionLength = TextFrom.SelLength;
		}

		private void pictureBox1_Paint(object sender, PaintEventArgs e)
		{
			Graphics graphics = e.Graphics;
			graphics.Clear(System.Drawing.Color.White);
			this.RefreshPreview(graphics);
		}

		private void RefreshPreview(Graphics g)
		{
			if (this.IsChange)
			{
				this.IsChange = false;
				List<CurveInfo> list = new List<CurveInfo>();
				ArcAxisCreator arcAxisCreator = new ArcAxisCreator(this.revit, this.revit.Application, this.m_dataFromDlg);
				CurveArray curveArray = arcAxisCreator.CreateLineAxisCurvesWithoutExtend(XYZ.Zero);
				CurveArray curveArray2 = arcAxisCreator.CreateArcAxisCurves(XYZ.Zero);
				CurveArray arcDimCurve = arcAxisCreator.GetArcDimCurve(curveArray2);
				CurveArray dimCurve = arcAxisCreator.GetDimCurve(curveArray2);
				if (curveArray.Size <= 0 || curveArray2.Size <= 0)
				{
					this.pictureBox3.Curves = list;
					return;
				}
				foreach (object obj in curveArray)
				{
					Curve curve = (Curve)obj;
					CurveInfo item = new CurveInfo(curve, PenColor.PC_Blue, 1f);
					list.Add(item);
					if (this.cbxRight.Checked)
					{
						if (this.m_dataFromDlg.ExtendL == 0.0)
						{
							XYZ center = curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve2 = this.m_docment.CreatYJKArc(center, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item2 = new CurveInfo(curve2, PenColor.PC_Blue, 1f);
							list.Add(item2);
						}
						else
						{
							Line curve3 = YJKLineEx.YJKGetBound(curve.GetEndPoint(0), curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendL));
							Line curve4 = YJKLineEx.YJKGetBound(curve.GetEndPoint(1), curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendL));
							XYZ center2 = curve3.GetEndPoint(1) + (curve3.GetEndPoint(1) - curve3.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve5 = this.m_docment.CreatYJKArc(center2, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item3 = new CurveInfo(curve5, PenColor.PC_Blue, 1f);
							CurveInfo item4 = new CurveInfo(curve3, PenColor.PC_Blue, 1f);
							CurveInfo item5 = new CurveInfo(curve4, PenColor.PC_Blue, 1f);
							list.Add(item4);
							list.Add(item5);
							list.Add(item3);
						}
					}
					if (this.cbxLeft.Checked)
					{
						if (this.m_dataFromDlg.ExtendL == 0.0)
						{
							XYZ center3 = curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve6 = this.m_docment.CreatYJKArc(center3, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item6 = new CurveInfo(curve6, PenColor.PC_Blue, 1f);
							list.Add(item6);
						}
						else
						{
							Line curve7 = YJKLineEx.YJKGetBound(curve.GetEndPoint(0), curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendL));
							Line curve8 = YJKLineEx.YJKGetBound(curve.GetEndPoint(1), curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendL));
							XYZ center4 = curve8.GetEndPoint(1) - (curve8.GetEndPoint(0) - curve8.GetEndPoint(1)).Normalize() * 1.5;
							Arc curve9 = this.m_docment.CreatYJKArc(center4, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item7 = new CurveInfo(curve9, PenColor.PC_Blue, 1f);
							CurveInfo item8 = new CurveInfo(curve7, PenColor.PC_Blue, 1f);
							CurveInfo item9 = new CurveInfo(curve8, PenColor.PC_Blue, 1f);
							list.Add(item8);
							list.Add(item9);
							list.Add(item7);
						}
					}
					if (!this.cbxRight.Checked && !this.cbxLeft.Checked && this.m_dataFromDlg.ExtendL != 0.0)
					{
						Line curve10 = YJKLineEx.YJKGetBound(curve.GetEndPoint(1), curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendL));
						Line curve11 = YJKLineEx.YJKGetBound(curve.GetEndPoint(0), curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendL));
						CurveInfo item10 = new CurveInfo(curve10, PenColor.PC_Blue, 1f);
						CurveInfo item11 = new CurveInfo(curve11, PenColor.PC_Blue, 1f);
						list.Add(item10);
						list.Add(item11);
					}
				}
				foreach (object obj2 in curveArray2)
				{
					Curve curve12 = (Curve)obj2;
					if (!(null == curve12))
					{
						Arc arc = curve12 as Arc;
						if (arc.Length != 0.0)
						{
							CurveInfo item12 = new CurveInfo(curve12, PenColor.PC_Red, 1f);
							list.Add(item12);
							XYZ xyz = arc.ComputeDerivatives(0.0, true).get_Basis(0);
							XYZ xyz2 = arc.ComputeDerivatives(1.0, true).get_Basis(0);
							if (this.cbxDown.Checked)
							{
								if (this.m_dataFromDlg.ExtendA == 0.0)
								{
									XYZ center5 = curve12.GetEndPoint(0) - xyz.Normalize() * 1.5;
									Arc curve13 = this.m_docment.CreatYJKArc(center5, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
									CurveInfo item13 = new CurveInfo(curve13, PenColor.PC_Red, 1f);
									list.Add(item13);
								}
								else
								{
									Line curve14 = YJKLineEx.YJKGetBound(arc.GetEndPoint(0), arc.GetEndPoint(0) - xyz.Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendA));
									Line curve15 = YJKLineEx.YJKGetBound(arc.GetEndPoint(1), arc.GetEndPoint(1) + xyz2.Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendA));
									XYZ center6 = curve14.GetEndPoint(1) + (curve14.GetEndPoint(1) - curve14.GetEndPoint(0)).Normalize() * 1.5;
									Arc curve16 = this.m_docment.CreatYJKArc(center6, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
									CurveInfo item14 = new CurveInfo(curve16, PenColor.PC_Red, 1f);
									CurveInfo item15 = new CurveInfo(curve14, PenColor.PC_Red, 1f);
									CurveInfo item16 = new CurveInfo(curve15, PenColor.PC_Red, 1f);
									list.Add(item15);
									list.Add(item16);
									list.Add(item14);
								}
							}
							if (this.cbxUp.Checked)
							{
								if (this.m_dataFromDlg.ExtendA == 0.0)
								{
									XYZ center7 = curve12.GetEndPoint(1) + xyz2.Normalize() * 1.5;
									Arc curve17 = this.m_docment.CreatYJKArc(center7, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
									CurveInfo item17 = new CurveInfo(curve17, PenColor.PC_Red, 1f);
									list.Add(item17);
								}
								else
								{
									Line curve18 = YJKLineEx.YJKGetBound(arc.GetEndPoint(1), arc.GetEndPoint(1) + xyz2.Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendA));
									Line curve19 = YJKLineEx.YJKGetBound(arc.GetEndPoint(0), arc.GetEndPoint(0) - xyz.Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendA));
									XYZ center8 = curve18.GetEndPoint(1) + (curve18.GetEndPoint(1) - curve18.GetEndPoint(0)).Normalize() * 1.5;
									Arc curve20 = this.m_docment.CreatYJKArc(center8, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
									CurveInfo item18 = new CurveInfo(curve20, PenColor.PC_Red, 1f);
									CurveInfo item19 = new CurveInfo(curve18, PenColor.PC_Red, 1f);
									CurveInfo item20 = new CurveInfo(curve19, PenColor.PC_Red, 1f);
									list.Add(item19);
									list.Add(item20);
									list.Add(item18);
								}
							}
							if (!this.cbxUp.Checked && !this.cbxDown.Checked && this.m_dataFromDlg.ExtendA != 0.0)
							{
								Line curve21 = YJKLineEx.YJKGetBound(arc.GetEndPoint(1), arc.GetEndPoint(1) + xyz2.Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendA));
								Line curve22 = YJKLineEx.YJKGetBound(arc.GetEndPoint(0), arc.GetEndPoint(0) - xyz.Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendA));
								CurveInfo item21 = new CurveInfo(curve21, PenColor.PC_Red, 1f);
								CurveInfo item22 = new CurveInfo(curve22, PenColor.PC_Red, 1f);
								list.Add(item21);
								list.Add(item22);
							}
						}
					}
				}
				if (this.checkBoxDim.Checked)
				{
					foreach (object obj3 in arcDimCurve)
					{
						Curve curve23 = (Curve)obj3;
						CurveInfo item23 = new CurveInfo(curve23, PenColor.PC_Green, 2f);
						list.Add(item23);
					}
					foreach (object obj4 in dimCurve)
					{
						Curve curve24 = (Curve)obj4;
						CurveInfo item24 = new CurveInfo(curve24, PenColor.PC_Green, 2f);
						list.Add(item24);
					}
				}
				this.pictureBox3.Curves = list;
				this.pictureBox3.ZoomExtents();
			}
		}

		private void gridView_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void textBoxInnerRadius_TextChanged(object sender, EventArgs e)
		{
			double num = 0.0;
			if (double.TryParse(this.textBoxInnerRadius.Text, out num) && num < 100000.0 && num >= 0.0)
			{
				this.m_dataFromDlg.InnerRadius = Convert.ToDouble(this.textBoxInnerRadius.Text);
				this.IsChange = true;
				this.pictureBox3.Refresh();
				return;
			}
			YJKMessageBox.Show("输入的值不合法。");
			this.m_dataFromDlg.InnerRadius = 3300.0;
			this.textBoxInnerRadius.Text = "3300";
		}

		private void gridView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
		{
			this.RefreshControls();
		}

		private void ArcAxisForm_Load(object sender, EventArgs e)
		{
			this.ShowHideMoreParam();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void AddRow1(List<AxisListItem> data, BindingSource bSource, double dist)
		{
			if (data.Count < 1)
			{
				bSource.Add(new AxisListItem(1, dist));
				return;
			}
			if (Geometry.IsEqual(data[data.Count - 1].Dist, 0.0))
			{
				int number = data[data.Count - 1].Number;
				bSource.List[bSource.List.Count - 1] = new AxisListItem(1, dist);
				bSource.ResetBindings(false);
				return;
			}
			bSource.Add(new AxisListItem(1, dist));
		}

		private void gridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			int rowIndex = e.RowIndex;
			if (rowIndex == this.gridView.RowCount - 1)
			{
				DataGridViewCell dataGridViewCell = this.gridView.Rows[rowIndex].Cells[0];
				if (dataGridViewCell.Value != null && dataGridViewCell.Value.ToString().CompareTo("0") == 0)
				{
					double dist = Convert.ToDouble(0);
					if (this.radioDist.Checked)
					{
						this.AddRow1(this.m_dataFromDlg.DistData, this.bindingSourceDist, dist);
					}
					else if (this.radioAngle.Checked)
					{
						this.AddRow1(this.m_dataFromDlg.AngleData, this.bindingSourceAngle, dist);
					}
					this.RefreshControls();
					this.IsChange = true;
					this.pictureBox3.Refresh();
					return;
				}
			}
			else if (rowIndex != -1)
			{
				if (e.Button == MouseButtons.Right)
				{
					this.gridView.ContextMenuStrip = this.cmsGirdView;
				}
				if (this.radioDist.Checked)
				{
					this.FilterNullRow(this.m_dataFromDlg.DistData);
				}
				else
				{
					this.FilterNullRow(this.m_dataFromDlg.AngleData);
				}
				this.gridView.Refresh();
			}
		}

		private void FilterNullRow(List<AxisListItem> data)
		{
			if (data.Count < 1)
			{
				return;
			}
			if (data.Count != this.gridView.RowCount)
			{
				return;
			}
			AxisListItem axisListItem = data[data.Count - 1];
			if (axisListItem.Number == 0 || object.Equals(axisListItem.Dist, 0.0))
			{
				data.RemoveAt(data.Count - 1);
			}
		}

		private void FilterNullRow()
		{
			if (this.m_PreviousDataSourceType == ArcAxisForm.DataSourceType.DST_NONE)
			{
				return;
			}
			if (this.m_PreviousDataSourceType == ArcAxisForm.DataSourceType.DST_DIST)
			{
				this.FilterNullRow(this.m_dataFromDlg.DistData);
				return;
			}
			this.FilterNullRow(this.m_dataFromDlg.AngleData);
		}

		private void pictureBox3_Paint(object sender, PaintEventArgs e)
		{
			Graphics graphics = e.Graphics;
			graphics.Clear(System.Drawing.Color.Black);
			this.RefreshPreview(graphics);
		}

		private void cbxUp_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void cbxRight_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void cbxDown_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void cbxLeft_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void extendL_TextChanged(object sender, EventArgs e)
		{
			if (!Common.IsValidating(this.extendL.Text, 0.0, 10000.0))
			{
				MessageBox.Show("请输入0～10000之间的整数");
				this.extendL.Text = this.m_dataFromDlg.ExtendL.ToString("f0");
				return;
			}
			this.m_dataFromDlg.ExtendL = Convert.ToDouble(this.extendL.Text);
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void extendA_TextChanged(object sender, EventArgs e)
		{
			if (!Common.IsValidating(this.extendA.Text, 0.0, 10000.0))
			{
				MessageBox.Show("请输入0～10000之间的整数");
				this.extendA.Text = this.m_dataFromDlg.ExtendA.ToString("f0");
				return;
			}
			this.m_dataFromDlg.ExtendA = Convert.ToDouble(this.extendA.Text);
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void textBoxYStart_MouseLeave(object sender, EventArgs e)
		{
			string text = this.textBoxYStart.Text;
			if (this.cmbYStyle.SelectedIndex == 0)
			{
				string largestAlpha = AxisNameManager.GetLargestAlpha(this.m_docment);
				if (AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
				{
					TaskDialog taskDialog = new TaskDialog("Error");
					taskDialog.MainInstruction = "Y向起始轴号已经存在，请重新输入";
					taskDialog.AddCommandLink((TaskDialogCommandLinkId)1001, "使用默认的字母轴号");
					taskDialog.AddCommandLink((TaskDialogCommandLinkId)1002, "手工输入轴号");
                    taskDialog.DefaultButton = (TaskDialogResult)1001;
					TaskDialogResult taskDialogResult = taskDialog.Show();
                    if ((int)taskDialogResult == 1001)
					{
						this.textBoxYStart.Text = largestAlpha;
						return;
					}
                    if ((int)taskDialogResult == 1002)
					{
						this.textBoxYStart.Focus();
						this.textBoxYStart.SelectAll();
						return;
					}
				}
			}
			else if (this.cmbYStyle.SelectedIndex == 1)
			{
				int largestNumber = AxisNameManager.GetLargestNumber(this.m_docment);
				if (AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
				{
					TaskDialog taskDialog2 = new TaskDialog("Error");
					taskDialog2.MainInstruction = "Y向起始轴号已经存在，请重新输入";
					taskDialog2.AddCommandLink((TaskDialogCommandLinkId)1001, "使用默认的数字轴号");
					taskDialog2.AddCommandLink((TaskDialogCommandLinkId)1002, "手工输入轴号");
                    taskDialog2.DefaultButton = (TaskDialogResult)1001;
					TaskDialogResult taskDialogResult2 = taskDialog2.Show();
                    if ((int)taskDialogResult2 == 1001)
					{
						this.textBoxYStart.Text = largestNumber.ToString();
						return;
					}
                    if ((int)taskDialogResult2 == 1002)
					{
						this.textBoxYStart.Focus();
						this.textBoxYStart.SelectAll();
					}
				}
			}
		}

		private void textBoxAngle_TextChanged(object sender, EventArgs e)
		{
			if (!Common.IsValidating(this.textBoxAngle.Text, 0.0, 360.0))
			{
				MessageBox.Show("请输入0～360之间的整数");
				this.textBoxAngle.Text = this.m_dataFromDlg.StartAngle.ToString("f0");
				return;
			}
			this.m_dataFromDlg.StartAngle = Convert.ToDouble(this.textBoxAngle.Text);
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void textBoxInnerRadius_Leave(object sender, EventArgs e)
		{
			double num = 0.0;
			if (double.TryParse(this.textBoxInnerRadius.Text, out num) && num < 100000.0 && num >= 0.0)
			{
				this.m_dataFromDlg.InnerRadius = Convert.ToDouble(this.textBoxInnerRadius.Text);
				return;
			}
			YJKMessageBox.Show("输入值不合理。");
			this.m_dataFromDlg.InnerRadius = 3300.0;
			this.textBoxInnerRadius.Text = "3300";
		}

		private void textBoxXStart_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (this.cmbXStyle.Text.Substring(0, 1) == "1")
			{
				if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
				{
					e.Handled = true;
					return;
				}
			}
			else if (!char.IsLetter(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void textBoxYStart_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (this.cmbXStyle.Text.Substring(0, 1) == "1")
			{
				if (!char.IsLetter(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
				{
					e.Handled = true;
					return;
				}
			}
			else if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void gridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
		}

		private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				if (this.gridView.SelectedRows.Count > 0)
				{
					DataGridViewRow dataGridViewRow = this.gridView.SelectedRows[0];
					if (!dataGridViewRow.IsNewRow)
					{
						this.gridView.Rows.Remove(dataGridViewRow);
					}
					this.IsChange = true;
					this.pictureBox3.Refresh();
				}
			}
			catch
			{
			}
		}

		private void gridView_SelectionChanged(object sender, EventArgs e)
		{
		}

		private void gridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right && e.RowIndex >= 0 && e.RowIndex < this.gridView.Rows.Count - 1)
			{
				if (!this.gridView.Rows[e.RowIndex].Selected)
				{
					this.gridView.ClearSelection();
					this.gridView.Rows[e.RowIndex].Selected = true;
				}
				if (this.gridView.SelectedRows.Count == 1 && e.ColumnIndex >= 0)
				{
					this.gridView.CurrentCell = this.gridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
				}
				this.cmsGirdView.Show(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y);
			}
		}

		private void 插入ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.gridView.CurrentRow == null || this.gridView.CurrentRow.IsNewRow)
			{
				return;
			}
			if (this.radioDist.Checked)
			{
				double dist;
				if (this.listDist.SelectedItem != null)
				{
					dist = Convert.ToDouble(this.listDist.SelectedItem);
				}
				else
				{
					dist = 1000.0;
				}
				this.bindingSourceDist.Insert(this.gridView.CurrentRow.Index + 1, new AxisListItem(1, dist));
			}
			else if (this.radioAngle.Checked)
			{
				double dist2;
				if (this.listDist.SelectedItem != null)
				{
					dist2 = Convert.ToDouble(this.listDist.SelectedItem);
				}
				else
				{
					dist2 = 10.0;
				}
				this.bindingSourceAngle.Insert(this.gridView.CurrentRow.Index + 1, new AxisListItem(1, dist2));
			}
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void 上移toolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.gridView.CurrentRow == null || this.gridView.CurrentRow.IsNewRow)
			{
				return;
			}
			if (this.gridView.CurrentRow.Index <= 0)
			{
				return;
			}
			this.MovePrevious();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void MovePrevious()
		{
			if (this.gridView.SelectedRows.Count > 0)
			{
				if (this.gridView.SelectedRows[0].IsNewRow)
				{
					return;
				}
				int index = this.gridView.CurrentRow.Index;
				int number = Convert.ToInt32(this.gridView.Rows[index].Cells[0].Value.ToString());
				double dist = Convert.ToDouble(this.gridView.Rows[index].Cells[1].Value.ToString());
				this.gridView.Rows.RemoveAt(index);
				if (this.radioDist.Checked)
				{
					this.bindingSourceDist.Insert(index - 1, new AxisListItem(number, dist));
				}
				else if (this.radioAngle.Checked)
				{
					this.bindingSourceAngle.Insert(index - 1, new AxisListItem(number, dist));
				}
				this.gridView.Rows[index - 1].Selected = true;
				this.gridView.CurrentCell = this.gridView.Rows[index - 1].Cells[0];
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void 下移toolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.gridView.CurrentRow == null || this.gridView.CurrentRow.IsNewRow)
			{
				return;
			}
			if (this.gridView.CurrentRow.Index >= this.gridView.RowCount - 2)
			{
				return;
			}
			this.MoveNext();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void MoveNext()
		{
			if (this.gridView.SelectedRows.Count > 0)
			{
				if (this.gridView.SelectedRows[0].IsNewRow)
				{
					return;
				}
				int index = this.gridView.CurrentRow.Index;
				int number = Convert.ToInt32(this.gridView.Rows[index].Cells[0].Value.ToString());
				double dist = Convert.ToDouble(this.gridView.Rows[index].Cells[1].Value.ToString());
				this.gridView.Rows.RemoveAt(index);
				if (this.radioDist.Checked)
				{
					this.bindingSourceDist.Insert(index + 1, new AxisListItem(number, dist));
				}
				else if (this.radioAngle.Checked)
				{
					this.bindingSourceAngle.Insert(index + 1, new AxisListItem(number, dist));
				}
				this.gridView.Rows[index + 1].Selected = true;
				this.gridView.CurrentCell = this.gridView.Rows[index + 1].Cells[0];
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void extendA_Leave(object sender, EventArgs e)
		{
			if (this.extendA.Text != "")
			{
				this.m_dataFromDlg.ExtendA = Convert.ToDouble(this.extendA.Text);
				return;
			}
			this.extendA.Text = "3000";
			this.m_dataFromDlg.ExtendA = Convert.ToDouble(this.extendA.Text);
		}

		private void extendL_Leave(object sender, EventArgs e)
		{
			if (this.extendL.Text != "")
			{
				this.m_dataFromDlg.ExtendL = Convert.ToDouble(this.extendL.Text);
				return;
			}
			this.extendL.Text = "3000";
			this.m_dataFromDlg.ExtendL = Convert.ToDouble(this.extendL.Text);
		}

		private void textBoxAngle_Leave(object sender, EventArgs e)
		{
			if (this.textBoxAngle.Text != "")
			{
				this.m_dataFromDlg.StartAngle = Convert.ToDouble(this.textBoxAngle.Text);
				return;
			}
			this.textBoxAngle.Text = "0";
			this.m_dataFromDlg.StartAngle = Convert.ToDouble(this.textBoxAngle.Text);
		}

		private ArcAxisForm.DataSourceType m_PreviousDataSourceType;

		public ArcAxisDataFromDlg m_dataFromDlg;

		private Document m_docment;

		private bool m_bExpand;

		private ExternalCommandData revit;

		private DataGridViewTextBoxEditingControl EditingControl = new DataGridViewTextBoxEditingControl();

		private ArcAxisForm.struPastText PastText;

		private bool IsChange;

		private DataGridViewTextBoxColumn Number;

		private DataGridViewTextBoxColumn Dist;

		private Previewer pictureBox3;

		private enum DataSourceType
		{
			DST_NONE,
			DST_DIST,
			DST_ANGLE
		}

		private struct struPastText
		{
			public struPastText(string txt, int Start, int Length)
			{
				this.Text = txt;
				this.SelStart = Start;
				this.SelLength = Length;
			}

			public string Text;

			public int SelStart;

			public int SelLength;
		}
	}
}
